import React, {Component} from 'react';

/**
 * 非受控组件demo
 */
class UncontrollableComponentDemo extends Component {
    constructor(props) {
        super(props);
        this.handleSubmit = this.handleSubmit.bind(this);
        this.change = this.change.bind(this);
        this.input = React.createRef();
        this.state = {value: 2};
    }

    handleSubmit(event) {
        alert('A name was submitted: ' + this.state.value);
        event.preventDefault();
    }

    change(event) {
        this.setState({value: event.target.value});
        // console.log(event.target.value);
    }

    render() {
        return (
            <form onSubmit={this.handleSubmit}>
                <label>
                    Name:
                    <input type="text" value={this.state.value} onChange={this.change}/> </label>
                <input type="submit" value="Submit"/>
            </form>
        );
    }
}

export default UncontrollableComponentDemo;